package com.weaponlin.optional;

import com.weaponlin.entity.User;

import java.util.Optional;

public class OPTEST {

    public static void main(String[] args) {
//        String str = "optionalString";
//        Optional<String> optional = Optional.ofNullable(str);
//        String s = optional.map(e -> e.length()).map(e -> e.toString()).orElse("0");
//        System.out.println(s);

//        Optional.ofNullable(new User()).map(e -> e.getPhone()).map(e -> e.get()).orElse(-1L);
//        Optional.ofNullable(new User()).flatMap(e -> e.getPhone()).orElse(-1L);

        User u = null;
        String s = Optional.ofNullable(u).map(User::getPhone).map(String::valueOf).orElse("-1");
        System.out.println(s);

        Optional.ofNullable(new User()).ifPresent(System.out::println);
    }
}
